home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume10 / cbar < prev    next >
Encoding:
Text File  |  1987-07-29  |  4.4 KB  |  198 lines

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v10i074:  Another changebar program
  5. Message-ID: <739@uunet.UU.NET>
  6. Date: 30 Jul 87 22:40:38 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 187
  9. Approved: rs@uunet.UU.NET
  10.  
  11. Submitted-by: Alan Crosswell <alan@columbia.edu>
  12. Posting-number: Volume 10, Issue 74
  13. Archive-name: cbar
  14.  
  15. [  Two similar programs in one day?  Consider it a test of software
  16.    Darwinism.  I wrote the Makefile.  --r$  ]
  17.  
  18. #! /bin/sh
  19. # This is a shell archive, meaning:
  20. # 1. Remove everything above the #! /bin/sh line.
  21. # 2. Save the resulting text in a file.
  22. # 3. Execute the file with /bin/sh (not csh) to create:
  23. #    Makefile
  24. #    cbar.l
  25. #    cbar.c
  26. export PATH; PATH=/bin:/usr/bin:$PATH
  27. if test -f 'Makefile'
  28. then
  29.     echo shar: "will not over-write existing file 'Makefile'"
  30. else
  31. cat << \SHAR_EOF > 'Makefile'
  32. ##  Makefile for cbar
  33. all:        cbar
  34. cbar:        cbar.c
  35.     $(CC) $(CFLAGS) -o cbar cbar.c
  36. install:    all
  37.     @echo cp cbar and cbar.l into local directories as appropriate
  38. SHAR_EOF
  39. fi
  40. if test -f 'cbar.l'
  41. then
  42.     echo shar: "will not over-write existing file 'cbar.l'"
  43. else
  44. cat << \SHAR_EOF > 'cbar.l'
  45. .TH CBAR LOCAL
  46. .SH NAME
  47. cbar \- add change bars to a document
  48. .SH SYNOPSIS
  49. .B cbar
  50. [
  51. .I bar-on bar-off
  52. ]
  53.  
  54. .SH DESCRIPTION
  55. .B Cbar
  56. inserts text-formatter commands into diff -e output to turn
  57. on and off change bars.  This can then be fed back into 
  58. .B ed(1)
  59. along with the original document to produce a new document
  60. that contains change bars wherever the new and old version of
  61. a document have differences.
  62.  
  63. .I bar-on
  64. and
  65. .I bar-off
  66. may be specified as the commands to turn on and off change bars,
  67. respecively.  If not specified, 
  68. .B @CBON
  69. and 
  70. .B @CBOFF
  71. (for Scribe) are used.
  72.  
  73. .SH EXAMPLE
  74. .nf
  75. diff -b -e old.mss new.mss | cbar | ed - old.mss >bars.mss
  76. .fi
  77. .SH SEE ALSO
  78. diff(1), ed(1)
  79.  
  80. .SH BUGS
  81. .B ed(1)
  82. commands on stdin must appear in decreasing line number order
  83. so that lines at the end of the file get edited first and lines at
  84. the beginning get edited last (diff -e does this).
  85. This restriction exists because additional lines are
  86. added to the file which will mess up the line numbering scheme if
  87. done in lowest-to-highest order.
  88. SHAR_EOF
  89. fi
  90. if test -f 'cbar.c'
  91. then
  92.     echo shar: "will not over-write existing file 'cbar.c'"
  93. else
  94. cat << \SHAR_EOF > 'cbar.c'
  95. static char *RCSid = "$Header: cbar.c,v 1.1 87/04/22 10:31:51 alan Exp $";
  96. /* 
  97.  * cbar [bar-on bar-off]
  98.  *
  99.  * Inserts change bar commands around diff -e output.  
  100.  *
  101.  * Alan Crosswell, Columbia University
  102.  *
  103.  * Tacks on a "1,$p" at the end so that you can do something like this:
  104.  *
  105.  *  diff -b -e old.mss updated.mss | cbar | ed - old.mss >updated-bar.mss
  106.  *
  107.  * Input looks like this:
  108.  *------------------------------
  109.  * 746,747d
  110.  * 138a
  111.  * NOTE: Change this for LISTSERV.
  112.  * .
  113.  * 89c
  114.  * followed by a blank or hyphen (e.g. "220 ").
  115.  * .
  116.  *------------------------------
  117.  * Output looks like:
  118.  *------------------------------
  119.  * 746,747d
  120.  * 138,138a
  121.  * @CBON
  122.  * NOTE: Change this for LISTSERV.
  123.  * @CBOFF
  124.  * .
  125.  * 91,91c
  126.  * @CBON
  127.  * followed by a blank or hyphen (e.g. "220 ").
  128.  * @CBOFF
  129.  * .
  130.  * 1,$p
  131.  *------------------------------
  132.  *
  133.  * NOTE:  It is imperitave that the line numbers appear in highest-first
  134.  *  order since extra lines are being added.
  135.  *
  136.  * The default change bar commands are those used by Scribe (@CBON, @CBOFF).
  137.  * You may provide your own (e.g. cbar ".mc |" ".mc" for nroff).
  138.  *
  139.  * $Log:    cbar.c,v $
  140.  * Revision 1.1  87/04/22  10:31:51  alan
  141.  * Initial revision
  142.  * 
  143.  * 
  144.  */
  145. #include <stdio.h>
  146.  
  147. static char *cbon = "@CBON";
  148. static char *cboff = "@CBOFF";
  149.  
  150. main(argc,argv)
  151. int argc;
  152. char **argv;
  153. {
  154.     char buf[1024];
  155.     enum {ed_cmd, in_data} state = ed_cmd;
  156.     
  157.     if (argc == 3) {
  158.     cbon = argv[1];
  159.     cboff = argv[2];
  160.     } else if (argc != 1) {
  161.     fprintf(stderr,"Usage: cbar [bar_on bar_off]\n");
  162.     exit(1);
  163.     }
  164.  
  165.     while(gets(buf) != NULL) {
  166.     switch (state) {
  167.       case ed_cmd:
  168.         if (buf[strlen(buf)-1] == 'd') {
  169.         state = ed_cmd;    /* 'd' has no data */
  170.         puts(buf);
  171.         } else {
  172.         state = in_data; /* 'a' and 'c' do */
  173.         printf("%s\n%s\n", buf, cbon);
  174.         }
  175.         break;
  176.  
  177.       case in_data:
  178.         if (buf[0] == '.' && buf[1] == '\0') { /* end of data */
  179.         state = ed_cmd;
  180.         printf("%s\n.\n", cboff);
  181.         } else
  182.           puts(buf);
  183.         break;
  184.     } /* end switch(state) */
  185.     } /* end while */
  186.     puts("1,$p");
  187. }
  188. SHAR_EOF
  189. fi
  190. exit 0
  191. #    End of shell archive
  192.  
  193. -- 
  194.  
  195. Rich $alz            "Anger is an energy"
  196. Cronus Project, BBN Labs    rsalz@bbn.com
  197. Moderator, comp.sources.unix    sources@uunet.uu.net
  198.